package org.example.config;

import org.example.utils.JwtInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * ClassName: WebMvcJavaConfig
 * Description:
 *
 * @Author Kotaro
 * @Create 2024/11/19 20:52
 * @Version 1.0
 */
@EnableWebMvc
@Configuration
@ComponentScan({"org.example.controller" , "org.example.exceptionhandler"})
public class WebMvcJavaConfig implements WebMvcConfigurer {

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB_INF/views/","jsp");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 JwtInterceptor 拦截器
        registry.addInterceptor(new JwtInterceptor())
                .addPathPatterns("/**")  // 配置需要拦截的路径（例如 `/api/*`）
                .excludePathPatterns("/ssm/user/login*", "/ssm/user/register*");  // 配置不需要拦截的路径（如登录、注册等）
    }
}
